**********************************************************************************************
*This file cleans the location of institutions using county FIPS and ZIP codes from the IPEDS*
**********************************************************************************************

*** create dta files from csv, labeling
cd "$raw_data_education/institutionDetails"

foreach i in 1989 1990 1991 {
cap do "$do_clean_education/IPEDS - do/do institutionDetails/ic`i'_hdr.do"
keep unitid city zip fips instnm control
gen year = `i'
	if `i'  != 1991 {
	tostring zip, replace 
	}
save "$clean_data_education/locationDatabase_`i'.dta", replace
clear
}
**************************************

foreach i in 1992 1993 1994 1995 {
cap do "$do_clean_education/IPEDS - do/do institutionDetails/ic`i'_a.do"
keep unitid city zip fips instnm control
gen year = `i'
tostring zip, replace 
save "$clean_data_education/locationDatabase_`i'.dta", replace
clear
}
**************************************

foreach i in 1999 {
cap do "$do_clean_education/IPEDS - do/do institutionDetails/ic`i'hd.do"
keep unitid city zip fips instnm control
gen year = `i'
tostring zip, replace 
save "$clean_data_education/locationDatabase_`i'.dta", replace
clear
}
**************************************

foreach i in 2000 2001 {
cap do "$do_clean_education/IPEDS - do/do institutionDetails/fa`i'hd.do"
keep unitid city zip fips instnm control
gen year = `i'
tostring zip, replace 
save "$clean_data_education/locationDatabase_`i'.dta", replace
clear
}
**************************************

foreach i in 2006 2007 2008 2013 2014 2015 {
cap do "$do_clean_education/IPEDS - do/do institutionDetails/fa`i'hd.do"
keep unitid city zip fips instnm control
gen year = `i'
save "$clean_data_education/locationDatabase_`i'.dta", replace
clear
}
**************************************
* append
use "$clean_data_education/locationDatabase_1989.dta", clear
foreach i in 1990 1991 1992 1993 1994 1995 1999 2000 2001 2006 2007 2008 2013 2014 2015 {
append using "$clean_data_education/locationDatabase_`i'.dta"
rm "$clean_data_education/locationDatabase_`i'.dta"
}

* final cleanings
run "$do_clean_education/clean institutions - id.do"

save "$clean_data_education/locationDatabase.dta", replace
rm "$clean_data_education/locationDatabase_1989.dta"

